/**
 * 
 */
package at.ac.tuwien.vpsbcm.spielzeugfabrik.space;

import java.util.Properties;

import org.mozartspaces.core.DefaultMzsCore;
import org.mozartspaces.core.MzsCore;
import org.mozartspaces.core.config.CommonsXmlConfiguration;
import org.mozartspaces.core.config.Configuration;
import org.mozartspaces.core.config.PersistenceConfiguration;
import org.mozartspaces.core.config.SecurityConfiguration;


/**
 * @author Andreas Wolf
 *
 */
public class Server {

    private Server() {
    }

    /**
     * Starts MozartSpaces with an embedded space in the stand-alone mode.
     *
     */
    public static void main(final String[] args) {
        System.out.println("Starting Spielzeugfabrik MozartSpaces Server");
        final MzsCore core;
        Configuration config = CommonsXmlConfiguration.load();
        PersistenceConfiguration pC = config.getPersistenceConfiguration();
        Properties pP;
        SecurityConfiguration sC = new SecurityConfiguration(false, false, false);
        config.setSecurityConfiguration(sC);
        config.setXpThreadNumber(18);
        
        if (args.length == 1) {
        	pC.setPersistenceProfile("berkeleydb-transactional-sync");
        	pP = pC.getPersistenceProperties();
        	pP.setProperty("berkeley-location", args[0]);
            config.setPersistenceConfiguration(pC);
            core = DefaultMzsCore.newInstance(config);
        } else {
        	System.out.println("Call syntax is: Server [<databasepath>] [-b]");
            core = DefaultMzsCore.newInstance(config);
        }
        System.out.println("Core is running and ready for requests");
        System.out.println("Press Ctrl+C to exit");
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                core.shutdown(true);
            }
        });
    }

}
